package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);not null;index:ip_idx commit:'账号'"`
	Password string `gorm:"type:varchar(36);not null;index:ip_idx commit:'密码'"`
	Status   string `gorm:"type:enum('正常','冻结');not null;index:ip_idx commit:'状态'"`
}

func (u *User) Find(username string) error {
	return DB.Debug().Where("username=?", username).Find(&u).Error
}

func (u *User) List(Status string) (user []*User) {
	if Status == "" {
		DB.Debug().Find(&user)
	} else {
		DB.Debug().Where("status=?", Status).Find(&user)
	}
	return
}
func (u *User) UsersStarts(Id int, Status string) (user []*User) {
	DB.Model(&user).Where("id", Id).Update("status", Status).Find(&user)
	return
}
